#include <func.h>
#define N 50000000
void *threadfunc(void *p)
{
    printf("I am subthread!\n");
    int i;
    long *sum=(long*)p;
    for(i=0;i<N;i++)
    {
        *sum+=1;
    }
    return NULL;
}
int main(int argc,char *argv[])
{
    int ret;
    int i;
    long sum=0;
    pthread_t pthid;
    ret=pthread_create(&pthid,NULL,threadfunc,&sum);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    printf("I am main thread\n");
    for(i=0;i<N;i++)
    {
        sum+=1;
    }
    pthread_join(pthid,NULL);
    printf("Current sum=%ld\n",sum);
    return 0;
}

